/**
 * Apr 4, 2010
 */
package org.tomale.id.gis;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;

/**
 * @author ferd
 *
 */
public class RenderManager {

	public final static String EXT_ID_RENDERERS = "org.tomale.id.gis.renderers";
	
	public static List<IRenderer> getRenderers(){
		ArrayList<IRenderer> ret = new ArrayList<IRenderer>();
		IConfigurationElement[] elems = Platform.getExtensionRegistry().getConfigurationElementsFor(EXT_ID_RENDERERS);
		for(IConfigurationElement elem : elems){
			if(!elem.getAttribute("class").isEmpty()){
				try {
					Object o = elem.createExecutableExtension("class");
					if(o instanceof IRenderer){
						ret.add((IRenderer) o);
					}
				}catch(CoreException e){
					Activator.logError(MessageFormat.format("Unable to create an instance of {0}.",
							elem.getAttribute("class")));
				}
			}
		}
		return ret;
	}
}
